#!/bin/bash
# Desc   : 应用设置环境变量
# Author : chun.yang@msxf.com
# Modify : 2017.05.24 by hongzheng.liu

## 设置JAVA路径 jenkins 使用发布时需要手动配置JAVA的环境变量
export JAVA_HOME=/opt/jdk1.8.0_112 
export JAVA=$JAVA_HOME/bin/java

## 设置springboot应用profile
[ -z "$SPRING_PROFILES_ACTIVE" ] && SPRING_PROFILES_ACTIVE=sit  # 需要根据环境修改

## 如果是config-server, 增加git库环境变量
if [ $APP_NAME == "configserver" ]; then
  ## 设置配置中心GIT库及访问用户
  [ -z "$CONFIG_GIT_REPO" ] && export CONFIG_GIT_REPO=http://10.247.11.8:90/cloud/config-repo.git # 需要根据环境修改
  [ -z "$CONFIG_GIT_LABEL" ] && export CONFIG_GIT_LABEL=master # 需要根据环境修改
  [ -z "$CONFIG_GIT_USERNAME" ] && export CONFIG_GIT_USERNAME=root # 需要根据环境修改
  [ -z "$CONFIG_GIT_PWD" ] && export CONFIG_GIT_PWD=zkjin@2017 # 需要根据环境修改
  ## AMQP
  [ -z "$RABBITMQ_HOST" ] && export RABBITMQ_HOST= # 需要根据环境修改
  [ -z "$RABBITMQ_ADDRESSES" ] && export RABBITMQ_ADDRESSES=10.247.11.8 # 需要根据环境修改
  [ -z "$RABBITMQ_VHOST" ] && export RABBITMQ_VHOST=springcloud # 需要根据环境修改
  [ -z "$RABBITMQ_USER" ] && export RABBITMQ_USER=springcloud # 需要根据环境修改
  [ -z "$RABBITMQ_PWD" ] && export RABBITMQ_PWD=springcloud # 需要根据环境修改
else
  ## 设置配置中心地址及访问用户
  [ -z "$CONFIG_SERVER_URI" ] && export CONFIG_SERVER_URI=http://10.247.11.8:8888 # 需要根据环境修改
  [ -z "$CONFIG_SERVER_USERNAME" ] && export CONFIG_SERVER_USERNAME=msxf # 需要根据配置需要修改
  [ -z "$CONFIG_SERVER_PASSWORD" ] && export CONFIG_SERVER_PASSWORD=msxf # 需要根据配置需要修改
fi

## 如果不是eureka-server, 增加keystore vault环境变量
if [ $APP_NAME != "eurekaserver" ]; then
  ## VAULT 配置信息
  [ -z "$VAULT_TOKEN" ] && export VAULT_TOKEN=06d947f3-61e1-69b1-2305-df76a6037d8d # 需要根据配置需要修改
  [ -z "$VAULT_HOST" ] && export VAULT_HOST=10.247.11.8  # 需要根据环境修改
  [ -z "$VAULT_PORT" ] && export VAULT_PORT=8200 # 需要根据环境修改

  ## KEYSTORE 密钥信息
  [ -z "$KEYSTORE_FILE" ] && export KEYSTORE_FILE=file:$CUR_PATH/server.jks # 需要根据配置需要修改
  [ -z "$KEYSTORE_PWD" ] && export KEYSTORE_PWD=msxf.com # 需要根据配置需要修改
  [ -z "$KEYSTORE_SECRET" ] && export KEYSTORE_SECRET=msxf.com # 需要根据配置需要修改
  [ -z "$KEYSTORE_ALIAS" ] && export KEYSTORE_ALIAS=msxf # 需要根据配置需要修改
fi
#pinpoint name长度截取
#PINPOINT_APP_NAME=`echo $APP_DOMAIN`
#localip=`/sbin/ip a | grep global| awk '{print $2}' | awk -F'/' '{print $1}'|cut -d . -f 4`
##增加PINPOINT监控java option
#if [ -f /opt/pinpoint-agent/pinpoint-bootstrap-1.6.2.jar ];then
#    PINPOINT="-javaagent:/opt/pinpoint-agent/pinpoint-bootstrap-1.6.2.jar -Dpinpoint.agentId=$APP_NAME-$localip-$APP_PORT -Dpinpoint.applicationName=$PINPOINT_APP_NAME"
#else
#    PINPOINT="-javaagent:/opt/pinpoint-agent/pinpoint-bootstrap-1.5.2.jar -Dpinpoint.agentId=$APP_NAME-$localip-$APP_PORT -Dpinpoint.applicationName=$PINPOINT_APP_NAME"
#fi

